/**
 * JAVACC DEMO 1.0
 * @copy right dwusoft company All rights reserved. 
 * @Package com.apache.info.service.plugins  
 */
package com.apache.info.service.plugins;

import java.util.Map;

import com.apache.api.vo.ParamsVo;
import com.apache.cache.util.Validator;
import com.apache.info.entity.PubInfoStatistics;
import com.apache.info.manager.PubInfoStatisticsManager;

/**
 * description:  主子表插入操作
 * @author dwusoft 创建时间：2015-10-15  
 * @Copyright(c)2014:北京--软件技术有限公司
 */
public class SubInsertInfoPluginImpl extends AbstractSubInfoPlugin {

	private PubInfoStatisticsManager pubInfoStatisticsManager;

	/**
	 * TODO 简单描述该方法的实现功能（可选）.  
	 * @see com.apache.info.service.plugins.AbstractSubInfoPlugin#doInvoke(com.apache.api.vo.ParamsVo)  
	 */
	protected Object doInvoke(ParamsVo vo) {
		String mark = "false";
		if (Validator.isNull(String.valueOf(vo.getParams("dyncSql")))) {//直接执行sql查询
			String sql = this.getDynicSql(vo, 1, String.valueOf(vo.getParams("mainSortCode")),
					String.valueOf(vo.getParams("mainTableName")));
			String subSql = this.getDynicSql(vo, 1, String.valueOf(vo.getParams("subSortCode")),
					String.valueOf(vo.getParams("subTableName")));
			vo.setParams("dyncSql", sql);
			vo.setParams("subDyncSql", subSql);
		}
		mark = InfoReleaseManager.saveInfo(vo);
		if ("true".equals(mark) && "true".equals(String.valueOf(vo.getParams("flagInfoStatistics")))) {//添加统计信息
			Map map = vo.getParams();
			ParamsVo pvo = new ParamsVo();
			PubInfoStatistics ps = new PubInfoStatistics();
			ps.setInfoId(Validator.generate());
			ps.setInfoUser(String.valueOf(map.get("createUser")));
			ps.setObjId(String.valueOf(map.get("infoId")));
			ps.setSortId(String.valueOf(vo.getParams("mainSortCode")));
			pvo.setObj(ps);
			pubInfoStatisticsManager.saveInfo(pvo);
		}
		return mark;
	}

	public void setPubInfoStatisticsManager(PubInfoStatisticsManager pubInfoStatisticsManager) {
		this.pubInfoStatisticsManager = pubInfoStatisticsManager;
	}

}
